/*     */ package com.engine;
/*     */ 
/*     */ import com.ui.SQUI;
/*     */ import java.io.BufferedReader;
/*     */ import java.io.IOException;
/*     */ import java.io.InputStreamReader;
/*     */ import java.io.PrintWriter;
/*     */ import java.net.Socket;
/*     */ import java.util.Observable;
/*     */ 
/*     */ public class Client extends Observable
/*     */   implements Runnable
/*     */ {
/*     */   private Socket socket;
/*     */   private BufferedReader br;
/*     */   private PrintWriter pw;
/*     */   private boolean connected;
/*  42 */   private int port = 5555;
/*     */ 
/*  47 */   private String hostName = "localhost";
/*     */ 
/*     */   public Client() {
/*  50 */     this.connected = false;
/*     */   }
/*     */ 
/*     */   public void connect(String hostName, int port) throws IOException {
/*  54 */     if (!this.connected)
/*     */     {
/*  56 */       this.hostName = hostName;
/*  57 */       this.port = port;
/*  58 */       this.socket = new Socket(hostName, port);
/*     */ 
/*  60 */       this.br = new BufferedReader(new InputStreamReader(this.socket.getInputStream()));
/*  61 */       this.pw = new PrintWriter(this.socket.getOutputStream(), true);
/*     */ 
/*  63 */       this.connected = true;
/*     */ 
/*  65 */       Thread t = new Thread(this);
/*  66 */       t.start();
/*     */     }
/*     */   }
/*     */ 
/*     */   public void sendMessage(String msg) throws IOException
/*     */   {
/*  72 */     if (this.connected)
/*  73 */       this.pw.println(msg);
/*  74 */     else throw new IOException("Not connected to server"); 
/*     */   }
/*     */ 
/*     */   public void disconnect()
/*     */   {
/*  78 */     if ((this.socket != null) && (this.connected))
/*     */       try
/*     */       {
/*  81 */         this.socket.close();
/*     */       }
/*     */       catch (IOException localIOException) {
/*     */       }
/*     */       finally {
/*  86 */         this.connected = false;
/*     */       }
/*     */   }
/*     */ 
/*     */   public void run()
/*     */   {
/*  92 */     String msg = "";
/*     */     try
/*     */     {
/*     */       do
/*     */       {
/*  97 */         SQUI.App.recv(msg);
/*     */ 
/*  99 */         setChanged();
/*     */ 
/* 101 */         notifyObservers(msg);
/*     */ 
/*  94 */         if (!this.connected) break; 
/*  94 */       }while ((msg = this.br.readLine()) != null);
/*     */     }
/*     */     catch (IOException localIOException)
/*     */     {
/*     */     }
/*     */     finally
/*     */     {
/* 105 */       this.connected = false;
/*     */     }
/*     */   }
/*     */ 
/*     */   public boolean isConnected() {
/* 109 */     return this.connected;
/*     */   }
/*     */ 
/*     */   public int getPort()
/*     */   {
/* 114 */     return this.port;
/*     */   }
/*     */ 
/*     */   public void setPort(int port) {
/* 118 */     this.port = port;
/*     */   }
/*     */ 
/*     */   public String getHostName() {
/* 122 */     return this.hostName;
/*     */   }
/*     */ 
/*     */   public void setHostName(String hostName) {
/* 126 */     this.hostName = hostName;
/*     */   }
/*     */ 
/*     */   public static void main(String[] argv) throws IOException
/*     */   {
/* 131 */     Client c = new Client();
/* 132 */     c.connect("localhost", 5555);
/* 133 */     BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
/* 134 */     String msg = "";
/* 135 */     while (!msg.equalsIgnoreCase("quit"))
/*     */     {
/* 137 */       msg = br.readLine();
/* 138 */       c.sendMessage(msg);
/*     */     }
/* 140 */     c.disconnect();
/*     */   }
/*     */ }

/* Location:           F:\16 2\SQ.jar
 * Qualified Name:     com.engine.Client
 * JD-Core Version:    0.6.0
 */